<template>
	<div>
		<el-container>
			<el-header>
				<h2>检验申请</h2>
			</el-header>
			<el-main>
				<div style="position: absolute; bottom: 10px; right: 10px;">总金额￥{{zongjine}}</div>
				<el-form ref="form" :model="form" label-width="80px">


					<el-form-item label="所在科室">
						<el-select v-model="form.keshi" placeholder="请选择当前所在科室">
							<el-option label="区域一" value="shanghai"></el-option>
							<el-option label="区域二" value="beijing"></el-option>
						</el-select>
					</el-form-item>


					<el-form-item label="病历号码">
						<el-input v-model="form.pid" prefix-icon="el-icon-edit"></el-input>
					</el-form-item>


					<el-form-item label="病人姓名">
						<el-input v-model="form.pname" prefix-icon="el-icon-edit"></el-input>
					</el-form-item>


					<el-form-item label="检验部门">
						<el-select @change="gaibian" v-model="form.jybumens" placeholder="请选择检验部门">
							<el-option v-for=" jybumen in JianyanXinxi.jybumens" :label="jybumen.jybumenname"
								:value="jybumen.jybumenname"></el-option>
						</el-select>
					</el-form-item>


					<el-form-item label="检验科目">
						<el-select v-model="form.jykemus" placeholder="请选择检验科目" multiple @change="gengxin">
							<el-option v-for="jykemu in truekemu"
								:label="jykemu.jykemuname+' 价格'+jykemu.price" :value="jykemu.jykemuname"></el-option>
						</el-select>
					</el-form-item>


					<el-form-item label="检验类型">
						<el-radio-group v-model="form.jykind">
							<el-radio label="普通" border></el-radio>
							<el-radio label="加急" border></el-radio>
						</el-radio-group>
					</el-form-item>


					<el-form-item label="医生备注">
						<el-input type="textarea" v-model="form.docbeizhu"></el-input>
					</el-form-item>


					<el-form-item>
						<el-button type="primary" @click="onSubmit">立即创建</el-button>
						<el-button>取消</el-button>
					</el-form-item>


				</el-form>
				<!-- <el-button type="primary" @click="gengxin">更新</el-button> -->
			</el-main>
		</el-container>
	</div>
</template>

<script>
	export default {

		data() {
			return {
				form: {
					keshi: '',
					pid: '',
					pname: '',
					jybumens: '',
					jykemus: [],
					jykind: '',
					docbeizhu: ''
				},
				zongjine: 0,
				JianyanXinxi: {},
				truekemu:[]
				
			}
		},
		mounted: function() {
			this.$axios.get('http://localhost:8080/JianyanXinxi.json').then((result) => {
				this.JianyanXinxi = result.data; //写法固定
				console.log(JianyanXinxi);

			}).catch((err) => {
				console.log(err);
			})
		},
		methods: {
			onSubmit() {
				console.log('submit!');
			},
			gaibian(event) {
				this.form.jykemus = [];
				let obj = {};
				obj = this.JianyanXinxi.jybumens.find((item) => {
									return item.jybumenname === this.form.jybumens;
								});
				console.log(obj);
				
				this.truekemu = obj.jykemus;
			},
			gengxin()
			{
				this.zongjine=0;
				for (let bumen of this.JianyanXinxi.jybumens) {
					
				    for(let kemu of bumen.jykemus)
					{
						for(let tkemu of this.form.jykemus)
						{
							if(kemu.jykemuname==tkemu)
							{
								this.zongjine+=kemu.price;
							}
						}
					}
				 }
			},
		
		}
	}
</script>

<style>

</style>
